﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SerialPort通信
{
    public partial class FrmQuickSet : Form
    {
        public FrmQuickSet()
        {
            InitializeComponent();
        }

        public string CmdName { get; set; }
        public string CmdContent { get; set; }

        public FrmQuickSet(string CmdName, string CmdContent)
        {
            InitializeComponent();
            this.textBox1.Text = CmdName;
            this.textBox2.Text = CmdContent;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string temp = this.textBox2.Text.Trim().Replace(" ", "");
            if (HexHelper.IsHexString(temp) && temp.Length % 2 == 0)
            {
                CmdName = this.textBox1.Text;
                CmdContent = this.textBox2.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("请检查命名格式是否为16进制，", "命令错误");
            }

            //Thread thread = new Thread(() =>
            //{
            //    if (label1.InvokeRequired)
            //    {
            //        this.label1.Invoke(new Action(() =>
            //        {
            //            this.label1.Text = textBox1.Text;
            //        }));
            //    }
            //});
            //thread.Start();
        }

        private void Cancel_Btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}